//package com.yunxin.core.domain.service.warn.impl;
//
//
//import cn.hutool.core.collection.CollUtil;
//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.yunxin.core.domain.external.warn.WarnUserPageDTO;
//import com.yunxin.core.domain.external.warn.WarnUserPageResultDTO;
//import com.yunxin.core.domain.model.warn.WarnUser;
//import com.yunxin.core.domain.model.warn.WarnUserType;
//import com.yunxin.core.domain.service.warn.IWarnUserService;
//import com.yunxin.core.infra.persistence.mapper.warn.WarnUserMapper;
//import com.yunxin.core.infra.persistence.mapper.warn.WarnUserTypeMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.Collection;
//import java.util.Collections;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
///**
// * <p>
// * 告警通知user 服务实现类
// * </p>
// *
// * @author author
// * @since 2024-05-13
// */
//@Service
//public class WarnUserServiceImpl extends ServiceImpl<WarnUserMapper, WarnUser> implements IWarnUserService {
//
//
//    @Autowired
//    private WarnUserTypeMapper warnUserTypeMapper;
//
//    @Override
//    public List<WarnUser> selectUserByType(int type) {
//
//
//        return this.baseMapper.selectUserByType(type);
//    }
//
//    @Override
//    public Page<WarnUserPageResultDTO> selectWarnUserPage(WarnUserPageDTO userPageDTO) {
//
//        Page<WarnUserPageResultDTO> pages = new Page<>(userPageDTO.getPageNum(), userPageDTO.getPageSize(), true);
//
//        this.baseMapper.selectWarnUserPage(pages, userPageDTO);
//        List<WarnUserPageResultDTO> records = pages.getRecords();
//
//        if (CollUtil.isNotEmpty(records)) {
//            List<Long> list = records.stream().map(WarnUserPageResultDTO::getId).toList();
//
//            List<WarnUserType> typeList = warnUserTypeMapper.selectList(Wrappers.<WarnUserType>lambdaQuery()
//                    .in(WarnUserType::getWarnUser, list)
//                    );
//
//            Map<Long, List<WarnUserType>> map = typeList.stream().collect(Collectors.groupingBy(WarnUserType::getWarnUser));
//            for (WarnUserPageResultDTO record : records) {
//                List<WarnUserType> warnUserTypes = map.get(record.getId());
//                if (CollUtil.isNotEmpty(warnUserTypes)) {
//                    record.setTypes(warnUserTypes.stream().map(WarnUserType::getWarnType).toList());
//                } else {
//                    record.setTypes(Collections.emptyList());
//                }
//            }
//        }
//        return pages;
//    }
//}
